package com.itheima.a_cookie;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class PathServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
			//创建cookie
			Cookie cookie1 = new Cookie("bkey", "bvalue");
			Cookie cookie2 = new Cookie("ckey", "cvalue");
			Cookie cookie3 = new Cookie("dkey", "dvalue");
			Cookie cookie4 = new Cookie("dkey", "ssss");
			
			//设置cookie的路径(注意：同一路径下不能有重名的cookie，有的话会覆盖，不同路径下可以有重名的cookie)
			cookie3.setPath(request.getContextPath()+"/aa/bb");
			//写回浏览器
			response.addCookie(cookie1);
			response.addCookie(cookie2);
			response.addCookie(cookie3);
			response.addCookie(cookie4);
		
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}
}